<?xml version="1.0" encoding="UTF-8"?>
 <grammar xmlns="http://relaxng.org/ns/structure/1.0">

  <start>
   <ref name="element-library"/>
  </start>
  
  <define name="element-library">
   <element name="library">
    <oneOrMore>
     <ref name="element-book"/>
    </oneOrMore>
   </element>
  </define>
  
  <define name="element-book">
   <element name="book">
    <attribute name="id"/>
    <attribute name="available"/>
    <ref name="element-isbn"/>
    <ref name="element-title"/>
    <oneOrMore>
     <ref name="element-author"/>
    </oneOrMore>
    <zeroOrMore>
     <ref name="element-character"/>
    </zeroOrMore>
   </element>
  </define>
  
  <define name="element-isbn">
   <element name="isbn">
    <text/>
   </element>
  </define>
  
  <define name="element-title">
   <element name="title">
    <attribute name="xml:lang"/>
    <text/>
   </element>
  </define>
  
  <define name="element-author">
   <element name="author">
    <attribute name="id"/>
    <ref name="element-name"/>
    <optional>
     <ref name="element-born"/>
    </optional>
    <optional>
     <ref name="element-died"/>
    </optional>
   </element>
  </define>
  
  <define name="element-name">
   <element name="name">
    <text/>
   </element>
  </define>
  
  <define name="element-born">
   <element name="born">
    <text/>
   </element>
  </define>
  
  <define name="element-died">
   <element name="died">
    <text/>
   </element>
  </define>
  
  <define name="element-character">
   <element name="character">
    <attribute name="id"/>
    <ref name="element-name"/>
    <optional>
     <ref name="element-born"/>
    </optional>
    <ref name="element-qualification"/>
   </element>
  </define>
  
  <define name="element-qualification">
   <element name="qualification">
    <text/>
   </element>
  </define>

 </grammar>
